import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long sum1 = 0, sum2 = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum1 += a[i];
        }
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
            sum2 += b[i];
        }
        long ret = 0;
        if (sum1 == sum2) {
            // 可以做到
            for (int i = 0; i < n; i++) {
                if (a[i] < b[i]) {
                    ret += b[i] - a[i];
                }
            }
        } else {
            ret = -1;
        }
        System.out.println(ret);
    }
}